Types of Structured Text Statement |
You can build structured text code using these statement types: |
Statement Type |
Examples |
Assignment Statement |
Assigns a
value to a variable. For example: |
Running := TRUE; |
Setpoints[0] := 12.5; |
Setpoints[1]
:= Setpoints[0] + 2.5; |
Function Call Statement |
Call a
function discarding the return value. For example: |
StartPump(); |
IncreaseTargetSetpoint( Increment:=5.5 ); |
IF Statement |
Choose
different statements to run depending on a condition. For example: |
IF Level < 2.5 THEN |
State :=
'Normal'; |
ELSE |
State :=
'High'; |
END_IF; |
CASE Statement |
Run a
block of statements based on a selector value. For example: |
CASE PumpState OF |
0:00 |
StateDescription := "Stopped"; |
1:00 |
StateDescription := "Running"; |
2:00 |
StateDescription := "Failed"; |
ELSE |
StateDescription := "Invalid"; |
END_CASE; |
FOR Statement |
Run
statements a defined number of times. For example: |
Sum := 0; |
FOR Index:=0 TO 3 DO |
Sum :=
Sum + Values[ Index ]; |
END_FOR; |
FOR EACH Statement |
Run
statements for each item in a collection. For example: |
FOR EACH Item IN Collection DO |
... |
END_FOR; |
WHILE Statement |
Run
statements while a condition is true. For example: |
Index := 0; |
Sum := 0; |
WHILE Index < 10 DO |
Sum :=
Sum + Values[ Index ]; |
Index :=
Index + 1; |
END_WHILE; |
REPEAT Statement |
Run
statements until a condition is true. For example: |
Index := 0; |
Sum := 0; |
REPEAT |
Sum :=
Sum + Values[ Index ]; |
Index :=
Index + 1; |
UNTIL Index >= 10 END_REPEAT; |
EXIT Statement |
Exit a
loop statement early. For example: |
FOR Idx:=0 TO 9 DO |
IF Flags[
Idx ] THEN |
EXIT; |
END_IF; |
END_FOR; |
RETURN Statement |
Return from a Program Unit early. For example: |
IF
ProcessedFinished THEN |
RETURN; |
END_IF; |
|
|
|
|